provider "alicloud" {
  region                = local.region
}

terraform {
  required_version      = "~> 0.12"  
  backend "oss" {
    bucket              = "deeproute-terraform-resources"
    key                 = "prod/services/mapping"
    tablestore_endpoint = "https://terraform-status.cn-shenzhen.ots.aliyuncs.com"
    tablestore_table    = "terraform_statelock_table"    
    region              = "cn-shenzhen"
  }
}

module "random" {
  source                = "../../../modules/alicloud/random-vswitch"
  vswitch_id            = ["vsw-wz98687uzatjexvp5m9cy", "vsw-wz97jhyaiv8tjp176c8q2", "vsw-wz9oyaj4stoqc7risarrt"]
}

module "rds" {
  source                      = "git@code.deeproute.ai:deeproute/ops-terraform.git//alicloud/rds/rds-instance?ref=module.v1.0.2"
  rds_instance_name           = local.fullname
  rds_vswitch_id              = [module.random.vswitch_id[0]]
  # rds_security_group_ids      = [module.sg.sg_id]
  tags                        = local.tags
  rds_security_ips            = ["127.0.0.1","192.168.9.0/24","192.168.7.0/24","192.168.8.0/24","192.168.16.0/22","192.168.12.0/22","183.2.181.215","183.2.181.216","183.2.181.217","183.2.181.218","183.61.62.40","183.61.62.41","183.61.62.42","183.61.62.43","183.61.62.44","183.61.62.45","183.61.62.46","183.61.62.47"]
  rds_engine                  = "PostgreSQL"
  rds_engine_version          = "13.0"
  rds_instance_type           = "pg.n2.xlarge.1"  //https://help.aliyun.com/document_detail/26312.html?spm=a2c4g.11186623.6.570.37b93fa0e1d4lf
  rds_instance_storage        = "200"
  # rds_instance_charge_type    = "Postpaid"
  rds_instance_charge_type    = "Prepaid"
  rds_period                  = 1
  rds_auto_renew              = true
  rds_username                = "superadmin"
  rds_kms_password            = "MDBkM2FjZTItNjExMC00ZDVhLWJiNjktMTZkNTBhYzkxNTlkgepvZQkTzn6nDGx0c+WS3eIU9Y8q8Y+pS2aE1SoE3vA2f8q2wN6Do96sENJtSv29"
  enable_rds_backup           = true   
}

module "rds_database" {
  source                      = "git@code.deeproute.ai:deeproute/ops-terraform.git//alicloud/rds/rds-databases?ref=module.v1.0.2"
  rds_instance_id             = module.rds.rds_id
  rds_database_name           = "mapping"
  rds_character_set           = "UTF8"
}

